package srm511;

import java.util.Arrays;

public class FiveHundredEleven {
    int[] cards;
    int n;

    public String theWinner(int[] cards) {
        this.cards = cards;
        this.n = cards.length;

        cache = new int[512][n + 1];
        for (int i = 0; i < cache.length; i++) {
            Arrays.fill(cache[i], -1);
        }
        int sol = solve(0, 0);
        return sol == 0 ? "Fox Ciel" : "Toastman";
    }

    int cache[][];

    private int solve(int mem, int usedCards) {
        if (cache[mem][usedCards] != -1) return cache[mem][usedCards];
        int remaining = n - usedCards;
        for (int card : cards) {
            if ((mem & card) != card) {
                int newMem = mem | card;
                if (newMem != 511) {
                    if (solve(newMem, usedCards + 1) == 1) {
                        cache[mem][usedCards] = 0;
                        return 0;
                    }
                }
                remaining--;
            }
        }
        if (remaining > 0) {
            if (solve(mem, usedCards + 1) == 1) {
                cache[mem][usedCards] = 0;
                return 0;
            }
        }
        return 1;
    }

}

